﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace VentAnalyServer
{
    public class ApiUtil
    {
        public static JObject MakeJsonResult(int code, object data, string msg)
        {
            return new JObject()
            {
                new JProperty("code", code),
                new JProperty("data", data),
                new JProperty("msg", msg),
            };
        }

        public static ContentResult MakeJsonContentResult(object content)
        {
            return new ContentResult { Content = JsonConvert.SerializeObject(content), ContentType = "application/json" };
        }

        public static ContentResult Ok(object data, string msg="")
        {
            return MakeJsonContentResult(MakeJsonResult(0, data, msg));
        }

        public static ContentResult Error(string msg = "")
        {
            return MakeJsonContentResult(MakeJsonResult(1, null, msg));
        }
    }
}
